package beans;

import core.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebService;
import persistence.*;
import utils.Picker;
import utils.ServiceResponse;

/**
 * @author Ivan and Roman
 */
@Stateless
@WebService(serviceName = "SP_WebService")
public class WebServiceBean {

    @Inject
    private IGameDAO gameDAO;
    @Inject
    private ITournamentDAO tournamentDAO;
    @Inject
    private ILeagueDAO leagueDAO;
    @Inject
    private IUserDAO userDAO;
    @Inject
    private IPlayerDAO playerDAO;
    @Inject
    private ITeamDAO teamDAO;
    @Inject
    private IDisciplineDAO disciplineDAO;
    @Inject
    private IGameContractDAO gameContractDAO;

    /**
     * Method for authorize the user to input in system
     *
     * @param dataInput The massiv of data to input in system: String[] =
     * {login, password}
     * @return Object "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    public String[][] authorize(String[] dataInput) {
        String[][] result = null;

        try {
            SysUser u = userDAO.authorize(dataInput[0], dataInput[1]);
            u.initialize(SysUser.class);

            result = Picker.picker(u);
        } catch (Exception e) {
            ServiceResponse sr = new ServiceResponse();
            sr.setErrorHappend(true);
            sr.setMessage(e.getMessage());
            result = Picker.picker(sr);
        }

        return result;

    }

    /**
     * Method for registrate the new user in system
     *
     * @param userData The massiv of data about new user: String[] = {firstname,
     * lastname, age, city, info, contact_information, e-mail, login, password,
     * repeat_password}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "registrate")
    public String[][] registrate(String[] userData) {
        String[][] answ = null;
        boolean isNotError = false;

        try {

            isNotError = userDAO.getEntityValidator().validate(userData);
            if (!isNotError) {
                throw new Exception(userDAO.getEntityValidator().getMessage());
            }

            SysUser newUser = new SysUser(null);
            newUser.setFirstname(userData[0]);
            newUser.setLastname(userData[1]);

            Date date = null;
            SimpleDateFormat sdf = new SimpleDateFormat("dd.mm.yyyy");
            date = sdf.parse(userData[2]);

            newUser.setAge(date);
            newUser.setCity(userData[3]);
            newUser.setInfo(userData[4]);
            newUser.setContactInformation(userData[5]);
            newUser.setEMail(userData[6]);
            newUser.setLogin(userData[7]);
            newUser.setPassword(userData[8]);

            userDAO.create(newUser);

            ServiceResponse sr = new ServiceResponse();
            sr.setEntityId(newUser.getSysUserId().intValueExact());
            sr.setErrorHappend(false);
            sr.setMessage(userDAO.getEntityValidator().getMessage());
            sr.setOperationFinished(true);
            sr.setserviceResponseId(0);

            answ = Picker.picker(sr);

        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);

        } finally {
            return answ;
        }
    }

    /**
     * Method for change the data about a user
     *
     * @param dataAboutUser The massiv a new data: String[] = {userId,
     * newFirstname, newLastname, newAge, newCity, newInfo,
     * newContact_information, newE-mail, newLogin}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changeProfileInfo")
    public String[][] changeProfileInfo(String[] data) {
        return null;
    }

    /**
     * Method for change the password
     *
     * @param data The massiv of data: String[] = { userId, oldPassword,
     * newPassword, repeat_newPassword}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changePassword")
    public String[][] changePassword(String[] data) {
        return null;
    }

    /**
     * Method for delete a user account
     *
     * @param userId Identificator of deleted user
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "removeProfile")
    public String[][] removeProfile(int userId) {
        return null;
    }

    /**
     * Method for getting the information about a user
     *
     * @param userId Identificator of user
     * @return Object "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    @WebMethod(operationName = "getUserByID")
    public String[][] getUserByID(int userId) {
        return null;
    }

    /**
     * Method for getting information about all users
     *
     * @return Objects "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    @WebMethod(operationName = "getAllUsers")
    public String[][] getAllUsers() {

        String[][] answ = null;
        try {

            Object[] o = userDAO.findAll().toArray();
            answ = Picker.picker(o);
        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for add a new league
     *
     * @param data The massiv of data: String[] = {ownerId, name, discipline_id,
     * date_of_inceprion, date_of_end}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "entityId". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "addLeague")
    public String[][] addLeague(String[] data) {
        String[][] answ = null;
        boolean isNotError = false;
        ServiceResponse sr = new ServiceResponse();

        try {
            isNotError = leagueDAO.getEntityValidator().validate(data);
            if (!isNotError) {
                throw new Exception(leagueDAO.getEntityValidator().getMessage());
            }

            League newLeague = new League(null);

            SysUser owner = userDAO.find(BigDecimal.valueOf(Integer.getInteger(data[0])));
            newLeague.setOwner(owner);

            newLeague.setName(data[1]);

            Discipline discipline = disciplineDAO.find(BigDecimal.valueOf(Integer.getInteger(data[2])));
            newLeague.setDisciplineId(discipline);

            Date date = null;
            SimpleDateFormat sdf = new SimpleDateFormat("dd.mm.yyyy");

            date = sdf.parse(data[3]);
            newLeague.setDateOfInception(date);
            date = sdf.parse(data[4]);
            newLeague.setDateOfEnd(date);

            leagueDAO.create(newLeague);

            sr.setEntityId(newLeague.getLeagueId().intValueExact());
            sr.setErrorHappend(false);
            sr.setMessage(tournamentDAO.getEntityValidator().getMessage());
            sr.setOperationFinished(true);
            sr.setserviceResponseId(0);

            answ = Picker.picker(sr);
        } catch (Exception e) {

            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for add a new tournament
     *
     * @param data The massiv of data: String[] = {ownerId, name, league_id,
     * date_of_inception, date_of_end}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "entityId". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "addTournament")
    public String[][] addTournament(String[] data) {
        String[][] answ = null;
        boolean isNotError = false;
        ServiceResponse sr = new ServiceResponse();

        try {
            isNotError = tournamentDAO.getEntityValidator().validate(data);
            if (!isNotError) {
                throw new Exception(tournamentDAO.getEntityValidator().getMessage());
            }

            Tournament newTournament = new Tournament(null);

            SysUser owner = userDAO.find(BigDecimal.valueOf(Integer.getInteger(data[0])));
            newTournament.setOwner(owner);

            newTournament.setName(data[1]);

            League league = leagueDAO.find(BigDecimal.valueOf(Integer.getInteger(data[2])));
            newTournament.setLeagueId(league);

            Date date = null;
            SimpleDateFormat sdf = new SimpleDateFormat("dd.mm.yyyy");

            date = sdf.parse(data[3]);
            newTournament.setDateOfInception(date);
            date = sdf.parse(data[4]);
            newTournament.setDateOfEnd(date);

            tournamentDAO.create(newTournament);

            sr.setEntityId(newTournament.getTournamentId().intValueExact());
            sr.setErrorHappend(false);
            sr.setMessage(tournamentDAO.getEntityValidator().getMessage());
            sr.setOperationFinished(true);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } catch (Exception e) {

            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for add new game
     *
     * @param data The massiv of data: String[] = {ownerId, tournament_id,
     * venue, date_of_competition, status, score}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "entityId". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "addGame")
    public String[][] addGame(String[] data) {
        String[][] answ = null;
        boolean isNotError = false;
        ServiceResponse sr = new ServiceResponse();
        try {

            isNotError = gameDAO.getEntityValidator().validate(data);
            if (!isNotError) {
                throw new Exception(gameDAO.getEntityValidator().getMessage());
            }

            Game newGame = new Game(null);

            SysUser owner = userDAO.find(BigDecimal.valueOf(Integer.parseInt(data[0])));
            newGame.setOwner(owner);

            Tournament tournament = tournamentDAO.find(BigDecimal.valueOf(Integer.parseInt(data[1])));
            newGame.setTournamentId(tournament);

            newGame.setVenue(data[2]);

            Date date = null;
            SimpleDateFormat sdf = new SimpleDateFormat("dd.mm.yyyy");
            date = sdf.parse(data[3]);

            newGame.setDateOfCompetition(date);

            newGame.setStatus(data[4]);
            newGame.setScore(data[5]);

            gameDAO.create(newGame);

            sr.setEntityId(newGame.getGameId().intValueExact());
            sr.setErrorHappend(false);
            sr.setMessage(gameDAO.getEntityValidator().getMessage());
            sr.setOperationFinished(true);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);

        } catch (Exception e) {

            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for add a new team
     *
     * @param data The massiv of data: String[] = {ownerId, name, discipline_id,
     * count_players}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "addTeam")
    public String[][] addTeam(String[] data) {
        String[][] answ = null;
        boolean isNotError = false;
        ServiceResponse sr = new ServiceResponse();

        try {
            isNotError = teamDAO.getEntityValidator().validate(data);
            if (!isNotError) {
                throw new Exception(teamDAO.getEntityValidator().getMessage());
            }

            Team newTeam = new Team(null);

            SysUser owner = userDAO.find(BigDecimal.valueOf(Integer.parseInt(data[0])));
            newTeam.setOwner(owner);

            newTeam.setName(data[1]);

            Discipline discipline = disciplineDAO.find(BigDecimal.valueOf(Integer.parseInt(data[2])));
            newTeam.setDisciplineId(discipline);

            newTeam.setCountPlayers(BigInteger.valueOf(Integer.parseInt(data[3])));

            teamDAO.create(newTeam);

            sr.setEntityId(newTeam.getTeamId().intValueExact());
            sr.setErrorHappend(false);
            sr.setMessage(teamDAO.getEntityValidator().getMessage());
            sr.setOperationFinished(true);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);

        } catch (Exception e) {

            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for add new player
     *
     * @param data The massiv of data: String[] = {ownerId, firstname, lastname}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "addPlayer")
    public String[][] addPlayer(String[] data) {
        String[][] answ = null;
        boolean isNotError = false;
        ServiceResponse sr = new ServiceResponse();

        try {
            isNotError = playerDAO.getEntityValidator().validate(data);
            if (!isNotError) {
                throw new Exception(playerDAO.getEntityValidator().getMessage());
            }

            Player newPlayer = new Player(null);

            SysUser owner = userDAO.find(BigDecimal.valueOf(Integer.parseInt(data[0])));
            newPlayer.setOwner(owner);

            newPlayer.setFirstname(data[1]);
            newPlayer.setLastname(data[2]);


            playerDAO.create(newPlayer);

            sr.setEntityId(newPlayer.getPlayerId().intValueExact());
            sr.setErrorHappend(false);
            sr.setMessage(playerDAO.getEntityValidator().getMessage());
            sr.setOperationFinished(true);
            sr.setserviceResponseId(0);

            answ = Picker.picker(sr);
        } catch (Exception e) {
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for change the league
     *
     * @param newData The massiv of new data: String[] = {league_id, newName,
     * newDiscipline_id, newDate_of_inception, newDate_of_end}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changeLeague")
    public String[][] changeLeague(String[] newData) {
        return null;
    }

    /**
     * Method for change the tournament
     *
     * @param newData The massiv of new data: String[] = {tournament_id,
     * newName, newLeague_id, newDate_of_inception, newDate_of_end}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changeTournament")
    public String[][] changeTournament(String[] newData) {
        return null;
    }

    /**
     * Method for change the game
     *
     * @param newData The massiv of new data: String[] = {game_id, newTeam_id_2,
     * newVenue, newDate_of_competition}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "entityId". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changeGame")
    public String[][] changeGame(String[] newData) {
        return null;
    }

    /**
     * Method for change the team
     *
     * @param newData The massiv of new data: String[] = {team_id, newName,
     * newDiscipline_id, newCount_players}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changeTeam")
    public String[][] changeTeam(String[] newData) {
        return null;
    }

    /**
     * Method for change the player
     *
     * @param newData The massiv of new data: String[] = {player_id,
     * newFirstname, newLastname}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changePlayer")
    public String[][] changePlayer(String[] newData) {
        return null;
    }

    /**
     * Method for delete the league!
     *
     * @param league_id Identificator of a league, which will be deleted
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "removeLeague")
    public String[][] removeLeague(int league_id) {
        return null;
    }

    /**
     * Method for delete the tournament
     *
     * @param tournament_id Identificator of a tournament, which will be deleted
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "removeTournament")
    public String[][] removeTournament(int tournament_id) {
        return null;
    }

    /**
     * Method for delete the game
     *
     * @param game_id Identificator of a game, which will be deleted
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "entityId". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "removeGame")
    public String[][] removeGame(int game_id) {
        return null;
    }

    /**
     * Method for delete the team
     *
     * @param team_id Identificator of a team, which will be deleted
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "removeTeam")
    public String[][] removeTeam(int team_id) {
        return null;
    }

    /**
     * Method for delete the player
     *
     * @param player_id Identificator of a player, which will be deleted!
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "removePlayer")
    public String[][] removePlayer(int player_id) {
        return null;
    }

    /**
     * Method for getting information about a league
     *
     * @param league_id Identificator of league
     * @return Object "league" with Attributes: "id", "owner", "discipline_id",
     * "name", "status", "winner_team_id", "date_of_inception", "date_of_end"
     */
    @WebMethod(operationName = "getLeagueByID")
    public String[][] getLeagueByID(int league_id) {
        return null;
    }

    /**
     * Method for getting information about a tournament
     *
     * @param tournament_id Identificator of tournament
     * @return Object "tournament" with Attributes: "id", "league_id", "owner",
     * "name", "date_of_inception", "date_of_end", "status", "group_stage",
     * "final_stage", "prize", "winner_team_id"
     */
    @WebMethod(operationName = "getTournamentByID")
    public String[][] getTournamentByID(int tournament_id) {
        String[][] answ = null;
        ServiceResponse sr = new ServiceResponse();
        try {
            Tournament tournament = tournamentDAO.find(BigDecimal.valueOf(tournament_id));
            tournament.initialize(Tournament.class);
            answ = Picker.picker(tournament);

        } catch (Exception e) {
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for getting information about a game
     *
     * @param game_id Identificator of game
     * @return Object "game" with Attributes: "id", "tournament_id",
     * "player_id", "owner", "status", "venue", "date_of_competition", "score",
     * "winner_team_id"
     */
    @WebMethod(operationName = "getGameByID")
    public String[][] getGameByID(int game_id) {
        return null;
    }

    /**
     * Method for getting information about a team
     *
     * @param team_id Identificator of team
     * @return Object "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_players"
     */
    @WebMethod(operationName = "getTeamByID")
    public String[][] getTeamByID(int team_id) {
        return null;
    }

    /**
     * Method for getting information about a player
     *
     * @param player_id Identificator of player
     * @return Object "player" with Attributes: "id", "rating_id", "owner",
     * "firstname", "lastname"
     */
    @WebMethod(operationName = "getPlayerByID")
    public String[][] getPlayerByID(int player_id) {
        return null;
    }

    /**
     * Method for getting information about a discipline
     *
     * @param discipline_id Identificator of discipline
     * @return Object "discipline" with Attributes: "id", "name", "rules"
     */
    @WebMethod(operationName = "getDisciplineByID")
    public String[][] getDisciplineByID(int discipline_id) {
        return null;
    }

    /**
     * Method for getting information about all leagues
     *
     * @return Objects "league" with Attributes: "id", "owner", "discipline_id",
     * "name", "status", "winner_team_id", "date_of_inception", "date_of_end"
     */
    @WebMethod(operationName = "getAllLeagues")
    public String[][] getAllLeagues() {
        String[][] answ = null;
        try {

            Object[] o = leagueDAO.findAll().toArray();
            answ = Picker.picker(o);
        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for getting information about all tournaments
     *
     * @return Objects "tournament" with Attributes: "id", "league_id", "owner",
     * "name", "date_of_inception", "date_of_end", "status", "group_stage",
     * "final_stage", "prize", "winner_team_id"
     */
    @WebMethod(operationName = "getAllTournaments")
    public String[][] getAllTournaments() {
        String[][] answ = null;
        try {

            Object[] o = tournamentDAO.findAll().toArray();
            answ = Picker.picker(o);
        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for getting information about all games
     *
     * @return Objects "game" with Attributes: "id", "tournament_id",
     * "player_id", "owner", "status", "venue", "date_of_competition", "score",
     * "winner_team_id"
     */
    @WebMethod(operationName = "getAllGames")
    public String[][] getAllGames() {
        String[][] answ = null;
        try {

            Object[] o = gameDAO.findAll().toArray();
            answ = Picker.picker(o);
        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for getting information about all teams
     *
     * @return Objects "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getAllTeams")
    public String[][] getAllTeams() {
        String[][] answ = null;
        try {

            Object[] o = teamDAO.findAll().toArray();
            answ = Picker.picker(o);
        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for getting information about all players
     *
     * @return Objects "player" with Attributes: "id", "rating_id", "owner",
     * "firstname", "lastname"
     */
    @WebMethod(operationName = "getAllPlayers")
    public String[][] getAllPlayers() {
        String[][] answ = null;
        try {

            Object[] o = playerDAO.findAll().toArray();
            answ = Picker.picker(o);
        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for getting information about all disciplines
     *
     * @return Objects "discipline" with Attributes: "id", "name", "rules"
     */
    @WebMethod(operationName = "getAllDisciplines")
    public String[][] getAllDisciplines() {
        String[][] answ = null;
        try {

            Object[] o = disciplineDAO.findAll().toArray();
            answ = Picker.picker(o);
        } catch (Exception e) {

            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for getting the owner of league
     *
     * @param league_id Identificator of league
     * @return Object "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    @WebMethod(operationName = "getOwnerByLeague")
    public String[][] getOwnerByLeague(int league_id) {
        return null;
    }

    /**
     * Method for getting the owner of tournament
     *
     * @param tournament_id Identificator of tournament
     * @return Object "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    @WebMethod(operationName = "getOwnerByTournament")
    public String[][] getOwnerByTournament(int tournament_id) {
        return null;
    }

    /**
     * Method for getting the owner of game
     *
     * @param game_id Identificator of game
     * @return Object "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    @WebMethod(operationName = "getOwnerByGame")
    public String[][] getOwnerByGame(int game_id) {
        return null;
    }

    /**
     * Method for getting the owner of team
     *
     * @param team_id Identificator of team
     * @return Object "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    @WebMethod(operationName = "getOwnerByTeam")
    public String[][] getOwnerByTeam(int team_id) {
        return null;
    }

    /**
     * Method for getting the owner of player
     *
     * @param player_id Identificator of player
     * @return Object "user" with Attributes: "id", "login", "firstname",
     * "lastname", "age", "city", "info", "e-mail", "contact_information"
     */
    @WebMethod(operationName = "getOwnerByPlayer")
    public String[][] getOwnerByPlayer(int player_id) {
        return null;
    }

    /**
     * Method for getting a league for tournament
     *
     * @param tournametn_id Identificator of tournament
     * @return Object "league" with Attributes: "id", "owner", "discipline_id",
     * "name", "status", "winner_team_id", "date_of_inception", "date_of_end"
     */
    @WebMethod(operationName = "getLeagueByTournament")
    public String[][] getLeagueByTournament(int tournament_id) {
        return null;
    }

    /**
     * Method for getting a league for game
     *
     * @param game_id Identificator of game
     * @return Object "league" with Attributes: "id", "owner", "discipline_id",
     * "name", "status", "winner_team_id", "date_of_inception", "date_of_end"
     */
    @WebMethod(operationName = "getLeagueByGame")
    public String[][] getLeagueByGame(int game_id) {
        return null;
    }

    /**
     * Method for getting information about all leagues for discipline
     *
     * @param discipline_id Identificator of discipline
     * @return Objects "league" with Attributes: "id", "owner", "discipline_id",
     * "name", "status", "winner_team_id", "date_of_inception", "date_of_end"
     */
    @WebMethod(operationName = "getLeaguesByDiscipline")
    public String[][] getLeaguesByDiscipline(int discipline_id) {
        return null;
    }

    /**
     * Method for getting information about all leagues for owner
     *
     * @param userId Identificator of owner
     * @return Objects "league" with Attributes: "id", "owner", "discipline_id",
     * "name", "status", "winner_team_id", "date_of_inception", "date_of_end"
     */
    @WebMethod(operationName = "getLeaguesByOwner")
    public String[][] getLeaguesByOwner(int userId) {
        return null;
    }

    /**
     * Method for getting information about all tournaments for league
     *
     * @param league_id Identificator of league
     * @return Objects "tournaments" with Attributes: "id", "league_id",
     * "owner", "name", "date_of_inception", "date_of_end", "status",
     * "group_stage", "final_stage", "prize", "winner_team_id"
     */
    @WebMethod(operationName = "getTournamentsByLeague")
    public String[][] getTournamentsByLeague(int league_id) {
        return null;
    }

    /**
     * Method for getting information about all tournaments for discipline
     *
     * @param discipline_id Identificator of discipline
     * @return Objects "tournament" with Attributes: "id", "league_id", "owner",
     * "name", "date_of_inception", "date_of_end", "status", "group_stage",
     * "final_stage", "prize", "winner_team_id"
     */
    @WebMethod(operationName = "getTournamentsByDiscipline")
    public String[][] getTournamentsByDiscipline(int discipline_id) {
        return null;
    }

    /**
     * Method for getting information about all tournaments for owner
     *
     * @param userId Identificator of owner
     * @return Objects "tournament" with Attributes: "id", "league_id", "owner",
     * "name", "date_of_inception", "date_of_end", "status", "group_stage",
     * "final_stage", "prize", "winner_team_id"
     */
    @WebMethod(operationName = "getTournamentsByOwner")
    public String[][] getTournamentsByOwner(int userId) {
        return null;
    }

    /**
     * Method for getting information about teams for game
     *
     * @param game_id Identificator of game
     * @return Two objects "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getTeamsByGame")
    public String[][] getTeamsByGame(int game_id) {
        String[][] answ = null;
        try {

            List<Team> teams = gameContractDAO.getTeamsByGame(game_id);


            answ = Picker.picker(teams.toArray());
        } catch (Exception e) {
            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }

    }

    /**
     * Method for getting information about teams for player
     *
     * @param player_id Identificator of player
     * @return Objects "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getTeamsByPlayer")
    public String[][] getTeamsByPlayer(int player_id) {
        return null;
    }

    /**
     * Method for getting information about teams for discipline
     *
     * @param discipline_id Identificator of discipline
     * @return Objects "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getTeamsByDiscipline")
    public String[][] getTeamsByDiscipline(int discipline_id) {
        return null;
    }

    /**
     * Method for getting information about teams for owner
     *
     * @param user_id Identificator of owner
     * @return Objects "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getTeamsByOwner")
    public String[][] getTeamsByOwner(int user_id) {
        return null;
    }

    /**
     * Method for getting information about games for league
     *
     * @param league_id Identificator of league
     * @return Objects "game" with Attributes: "id", "tournament_id",
     * "player_id", "owner", "status", "venue", "date_of_competition", "score",
     * "winner_team_id"
     */
    @WebMethod(operationName = "getGamesByLeague")
    public String[][] getGamesByLeague(int league_id) {
        return null;
    }

    /**
     * Method for getting information about games for tournament
     *
     * @param tournament_id Identificator of tournament
     * @return Objects "game" with Attributes: "id", "tournament_id",
     * "player_id", "owner", "status", "venue", "date_of_competition", "score",
     * "winner_team_id"
     */
    @WebMethod(operationName = "getGamesByTournament")
    public String[][] getGamesByTournament(int tournament_id) {
        String[][] answ = null;
        try {
            Set<Game> games = gameDAO.getGamesByTournament(tournament_id);
            answ = Picker.picker(games.toArray());

        } catch (Exception e) {
            ServiceResponse sr = new ServiceResponse();
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }

    }

    /**
     * Method for getting information about games for team
     *
     * @param team_id Identificator of team
     * @return Objects "game" with Attributes: "id", "tournament_id",
     * "player_id", "owner", "status", "venue", "date_of_competition", "score",
     * "winner_team_id"
     */
    @WebMethod(operationName = "getGamesByTeam")
    public String[][] getGamesByTeam(int team_id) {
        return null;
    }

    /**
     * Method for getting information about games for owner
     *
     * @param userId identificator of owner
     * @return Objects "game" with Attributes: "id", "tournament_id",
     * "player_id", "owner", "status", "venue", "date_of_competition", "score",
     * "winner_team_id"
     */
    @WebMethod(operationName = "getGamesByOwner")
    public String[][] getGamesByOwner(int userId) {
        return null;
    }

    /**
     * Method for getting information about games for player
     *
     * @param player_id Identificator of player
     * @return Objects "game" with Attributes: "id", "tournament_id",
     * "player_id", "owner", "status", "venue", "date_of_competition", "score",
     * "winner_team_id"
     */
    @WebMethod(operationName = "getGamesByPlayer")
    public String[][] getGamesByPlayer(int player_id) {
        return null;
    }

    /**
     * Method for getting information about players for team
     *
     * @param team_id Identificator of team
     * @return Objects "player" with Attributes: "id", "rating_id", "owner",
     * "firstname", "lastname"
     */
    @WebMethod(operationName = "getPlayersByTeam")
    public String[][] getPlayersByTeam(int team_id) {
        return null;
    }

    /**
     * Method for getting information about players for game
     *
     * @param game_id Identificator of game
     * @return Objects "player" with Attributes: "id", "rating_id", "owner",
     * "firstname", "lastname"
     */
    @WebMethod(operationName = "getPlayersByGame")
    public String[][] getPlayersByGame(int game_id) {
        return null;
    }

    /**
     * Method for getting information about players for owner
     *
     * @param userId Identificator of owner
     * @return Objects "player" with Attributes: "id", "rating_id", "owner",
     * "firstname", "lastname"
     */
    @WebMethod(operationName = "getPlayersByOwner")
    public String[][] getPlayersByOwner(int userId) {
        return null;
    }

    /**
     * Method for change a rating of team
     *
     * @param dataRating The massiv of data: String[] = {team_id, achievements,
     * score}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changeRatingOfTeam")
    public String[][] changeRatingOfTeam(String[] dataRating) {
        return null;
    }

    /**
     * Method for getting information about rating for team
     *
     * @param team_id Identificator of team
     * @return Object "rating" with Attributes: "id", "victory", "lose_out",
     * "draw", "achievements", "score"
     */
    @WebMethod(operationName = "getRatingOfTeam")
    public String[][] getRatingOfTeam(int team_id) {
        return null;
    }

    /**
     * Method for change rating of player
     *
     * @param dataRating The massiv of data: String[] = {player_id,
     * achievements, score}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "changeRatingOfPlayer")
    public String[][] changeRatingOfPlayer(String[] dataRating) {
        return null;
    }

    /**
     * Method for getting information about rating for player
     *
     * @param player_id Identificator of player
     * @return Object "rating" with Attributes: "id", "victory", "lose_out",
     * "draw", "achievements", "score"
     */
    @WebMethod(operationName = "getRatingOfPlayer")
    public String[][] getRatingOfPlayer(int player_id) {
        String[][] answ = null;
        ServiceResponse sr = new ServiceResponse();
        try {
            Rating rating = playerDAO.getRatingOfPlayer(player_id);
            if (rating == null) {
                throw new Exception("!!!!!!!rating not exists!!!!!!!!!");
            }
            rating.initialize(Rating.class);
            answ = Picker.picker(rating);
        } catch (Exception e) {

            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }
    }

    /**
     * Method for setting a winner in the league
     *
     * @param dataWinner The massiv of data: int[] = {league_id, team_id}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "setWinnerOfLeague")
    public String[][] setWinnerOfLeague(int[] dataWinner) {
        return null;
    }

    /**
     * Method for getting a winner in the league
     *
     * @param league_id Identificator of league
     * @return Object "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getWinnerOfLeague")
    public String[][] getWinnerOfLeague(int league_id) {
        return null;
    }

    /**
     * Method for setting a winner in the tournament
     *
     * @param dataWinner The massiv of data: int[] = {tournament_id, team_id}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "setWinnerOfTournament")
    public String[][] setWinnerOfTournament(int[] dataWinner) {
        return null;
    }

    /**
     * Method for getting a winner in the tournament
     *
     * @param tournament_id Identificator of tournament
     * @return Object "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getWinnerOfTOurnament")
    public String[][] getWinnerOfTournament(int tournament_id) {
        return null;
    }

    /**
     * Method for setting a winner in the game
     *
     * @param dataWinner The massiv of data: int[] = {game_id, team_id}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "setWinnerOfGame")
    public String[][] setWinnerOfGame(int[] dataWinner) {
        return null;
    }

    /**
     * Method for getting a winner in the game
     *
     * @param game_id Identificator of game!
     * @return Object "team" with Attributes: "id", "name", "rating_id",
     * "discipline_id", "owner", "count_of_players"
     */
    @WebMethod(operationName = "getWinnerOfGame")
    public String[][] getWinnerOfGame(int game_id) {
        return null;
    }

    /**
     * Method for add a player in the team
     *
     * @param data The massiv of data: int[] = {team_id, player_id}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "addPlayerInTeam")
    public String[][] addPlayerInTeam(int[] data) {
        return null;
    }

    /**
     * Method for add teams in the game
     *
     * @param data The massiv of data: int[] = {game_id, team_id}
     * @return Object "serviceResponse" with Attributes: Attributes: "id",
     * "errorHappend", "errorId", "operationFinished", "message", "idEntity". If
     * "errorHappend" = true, then transfer Object "error" with Attributes:
     * "id", "description", "exceptionOfErrorStr", "rate", "number",
     * "objectIdWhereOccurred"
     */
    @WebMethod(operationName = "addTeamInGame")
    public String[][] addTeamInGame(int[] data) {
        String[][] answ = null;
        ServiceResponse sr = new ServiceResponse();

        try {

            Game game = gameDAO.find(BigDecimal.valueOf(data[0]));

            Team team = teamDAO.find(BigDecimal.valueOf(data[1]));

            GameContract gameContract = new GameContract(null);
            gameContract.setGameId(game);
            gameContract.setTeamId(team);

            gameContractDAO.create(gameContract);

            sr.setEntityId(gameContract.getGameContractId().intValueExact());
            sr.setMessage("team added in game!");
            sr.setErrorHappend(false);
            sr.setOperationFinished(true);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } catch (Exception e) {
            sr.setErrorId(e.hashCode());
            sr.setMessage(e.getMessage());
            sr.setErrorHappend(true);
            sr.setOperationFinished(false);
            sr.setserviceResponseId(sr.hashCode());

            answ = Picker.picker(sr);
        } finally {
            return answ;
        }


    }
}
